import { put, call } from 'redux-saga/effects'
import axios from '@/utils/request.js'

import { message } from 'antd';

// 拼团商品数据
function* getpinShop() {

    const res = yield call(axios, { url: "/api/getpinShop", method: "post" })
    // console.log(res, 'res');

    yield put({
        type: "GET_PINSHOP",
        payload: res
    })
}

// 拼团开关改变
function* getpinSwitch(payload) {
    // console.log(payload, 'payload');
    const res = yield call(axios, {
        url: "/api/getpinSwitch",
        method: "post",
        data: {
            id: payload.payload.id,
            status: payload.payload.status
        }
    })
    console.log(res, 'res');

}


// 拼团商品删除
function* getpinDelete(payload) {
    // console.log(payload.payload.id, 'payload');
    const res = yield call(axios, { url: "/api/getpinDelete", method: "post", data: { id: payload.payload.id } })
    // console.log(res, 'res');

    if (res.affectedRows === 1) {
        message.success('删除成功');
    } else {
        message.error('删除失败');
    }
}

// 拼团商品数据模糊搜索
function* getpinSearch(payload) {
    // console.log(payload, 'payload');

    const res = yield call(axios, { url: "/api/getpinShop", method: "post", data: { keyword: payload.payload.keyword } })
    // console.log(res, 'res');

    yield put({
        type: "GET_PINSEARCH",
        payload: res
    })
}

// 拼团商品拼团状态
function* getpinPinz(payload) {
    // console.log(payload, 'payload');

    const res = yield call(axios, { url: "/api/getpinShop", method: "post", data: { pinZ: payload.payload.pinZ } })
    // console.log(res, 'res');

    yield put({
        type: "GET_PINPINZ",
        payload: res
    })
}


export {
    getpinShop,
    getpinSwitch,
    getpinDelete,
    getpinSearch,
    getpinPinz
}